package com.red.work.demo;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.concurrent.TimeUnit;

/**
 * 测试调试类
 */
public class ChromeTest {

    public static void main(String[] args) throws Exception {
        //下载的chromedriver位置
        System.setProperty("webdriver.chrome.driver","/Users/nrq/code/gitee/work/src/main/java/com/red/work/chrome/chromedriver");

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("user-data-dir=/Users/nrq/Library/Application Support/Google/Chrome/Default");

        //实例化ChromeDriver对象
        WebDriver driver = new ChromeDriver(chromeOptions);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        System.out.println("-----------" + chromeOptions + "----------");

        String url="http://www.baidu.com/";
        //打开指定网站
        driver.get(url);

        driver.findElement(By.xpath("//*[@id=\"s-top-loginbtn\"]")).click();

        driver.findElement(By.xpath("//*[@id=\"main\"]/div[1]/div[3]/form/div/div/table/tbody/tr[1]/td[1]/div[1]"));
        driver.findElement(By.xpath("//*[@id=\"main\"]/div[1]/div[3]/form/div/div/table/tbody/tr[1]/td[1]/div[2]"));
        driver.findElement(By.xpath("//*[@id=\"main\"]/div[1]/div[3]/form/div/div/table/tbody/tr[1]/td[2]/div[1]/div"));
        driver.findElement(By.xpath("//*[@id=\"main\"]/div[1]/div[3]/form/div/div/table/tbody/tr[1]/td[2]/div[1]/p/i"));

        Thread.sleep(1000);

        driver.findElement(By.id("TANGRAM__PSP_11__footerULoginBtn")).click();

        // 输入账号密码
        driver.findElement(By.id("TANGRAM__PSP_11__userName")).sendKeys("残锅");
        driver.findElement(By.id("TANGRAM__PSP_11__password")).sendKeys("");

        // 登陆
        driver.findElement(By.id("TANGRAM__PSP_11__submit")).click();

        Thread.sleep(1000);

        driver.close();
    }

}
